/**
 * 加载通用类
 * @param {*} app
 */
function loadCommClass(app) {
  const filePath = __dirname + "/../../../comm/";
  //加载文件
  require("young-require-all")({
    dirname: filePath,
    filter: /(.+)\.ts$/,
    resolve: function (Service) {
      for (let ServiceName in Service) {
        const name = Service[ServiceName].name;
        if (app.comm[name])
          throw new Error(`comm class name repeat: ${ServiceName}!`);
        app.comm[name] = new Service[ServiceName]();
        app.log.info(
          `comm [${name}] loaded successfully, usage: this.app.comm.${name}`,
          true
        );
      }
    },
  });
  return async function (ctx, next) {
    await next();
  };
}
module.exports = { loadCommClass };
